home *** CD-ROM | disk | FTP | other *** search
/ Java Internet Programming Reference Guide / Java Internet Programming Reference Guide.iso / autorun / java.dir / 00137_cans.txt < prev    next >
Encoding:
Text File  |  1996-01-12  |  5.2 KB  |  246 lines

  1. Event handlers
  2.  
  3.  
  4.  
  5. The following event handlers are available in JavaScript: 
  6.  
  7. onBlur onChange onClick onFocus onLoad onMouseOver onSelect onSubmit onUnload 
  8. ---------------------------------------------------------
  9.  
  10.  
  11. onBlur event handler
  12.  
  13.  
  14.  
  15. A blur event occurs when a text or textArea field on a form loses focus. The onBlur event handler executes JavaScript code when a blur event occurs. 
  16.  
  17. Applies to
  18.  
  19.  
  20.  
  21. selection, text, textArea 
  22.  
  23. Examples
  24.  
  25.  
  26.  
  27. xxx Examples to be supplied. 
  28. ---------------------------------------------------------
  29.  
  30.  
  31. onChange event handler
  32.  
  33.  
  34.  
  35. A change event occurs when a selection, text, or textArea field loses focus and its value has been modified. The onChange event handler executes JavaScript code when a change event occurs. 
  36.  
  37. Use the onChange event handler to validate data after it is modified by a user. 
  38.  
  39. Applies to
  40.  
  41.  
  42.  
  43. selection, text, textArea 
  44.  
  45. Examples
  46.  
  47.  
  48.  
  49. xxx Examples to be supplied. 
  50. ---------------------------------------------------------
  51.  
  52.  
  53. onClick event handler
  54.  
  55.  
  56.  
  57. For button or radioButton, JavaScript code to run when a button is clicked. For checkbox, JavaScript code to run when user checks or unchecks an item. 
  58.  
  59.  
  60.  
  61. Applies to
  62.  
  63.  
  64.  
  65. button, checkbox, radioButton, link, reset, submit 
  66.  
  67. Examples
  68.  
  69.  
  70.  
  71. For example, suppose you have created a JavaScript function called compute(). You can execute the compute() function when the user clicks a button by calling the function in the onClick event handler, as follows: 
  72.  
  73. <INPUT TYPE="button"VALUE="Calculate"onClick="compute(this.form)"gt
  74.  
  75.  
  76.  
  77.  
  78. In the above example, the keyword this refers to the current object; in this case, the Calculate button. The construct this.form refers to the form containing the button. 
  79.  
  80. For another example, suppose you have created a JavaScript function called pickRandomURL() that lets you select a URL at random. You can use the onClick event handler of an anchor to dynamically specify a value for the HREF attribute of the anchor, as shown in the following example: 
  81.  
  82. <A HREF=""
  83.    onClick="this.href=pickRandomURL();"
  84.    onMouseOver="window.status='Pick a random URL'; return true">
  85. Go!</A>
  86.  
  87.  
  88.  
  89.  
  90. In the above example, the onMouseOver event handler specifies a custom message for the Navigator status bar when the user places the mouse pointer over the Go! anchor. As this example shows, you must return true to set the window.status property in the onMouseOver event handler. 
  91. ---------------------------------------------------------
  92.  
  93.  
  94. onFocus event handler
  95.  
  96.  
  97.  
  98. Executed when input focus enters the field, either by tabbing in or by clicking but not selecting in the field. 
  99.  
  100. Applies to
  101.  
  102.  
  103.  
  104. selection, text, textArea 
  105.  
  106. Examples
  107.  
  108.  
  109.  
  110. xxx Examples to be supplied. 
  111. ---------------------------------------------------------
  112.  
  113.  
  114. onLoad event handler
  115.  
  116.  
  117.  
  118. A load event occurs when Navigator finishes loading a window or all frames within a FRAMESET. The onLoad event handler executes JavaScript code when a load event occurs. 
  119.  
  120. Use the onLoad event handler within either the <BODY>or the <FRAMESET>tag, for example, <BODY onLoad="...">/TT>. 
  121.  
  122. Applies to
  123.  
  124.  
  125.  
  126. document, window 
  127.  
  128. Examples
  129.  
  130.  
  131.  
  132. xxx Examples to be supplied. 
  133.  
  134. See also
  135.  
  136.  
  137.  
  138. onUnload event handler 
  139. ---------------------------------------------------------
  140.  
  141.  
  142. onMouseOver event handler
  143.  
  144.  
  145.  
  146. Executes when the mouse pointer is over an object. You must return true if you want to set the window.status property with the onMouseOver event handler. 
  147.  
  148. Applies to
  149.  
  150.  
  151.  
  152. link 
  153.  
  154. Examples
  155.  
  156.  
  157.  
  158. By default, the HREF value of an anchor displays in the status bar at the bottom of the Navigator when a user places the mouse pointer over the anchor. In the following example, the onMouseOver event handler provides the custom message "Click this if you dare." 
  159.  
  160. <A HREF="http://home.netscape.com/"
  161.    onMouseOver="window.status='Click this if you dare!'; return true">
  162. Click me</A>
  163.  
  164.  
  165.  
  166.  
  167. See onClick for an example of using onMouseOver when the anchor HREF attribute is set dynamically. 
  168. ---------------------------------------------------------
  169.  
  170.  
  171. onSelect event handler
  172.  
  173.  
  174.  
  175.  
  176.  
  177. A select event occurs when a user selects some of the text within a text or textArea field. The onSelect event handler executes JavaScript code when a select event occurs. 
  178.  
  179. Applies to
  180.  
  181.  
  182.  
  183. text, textArea 
  184.  
  185. Examples
  186.  
  187.  
  188.  
  189. xxx Examples to be supplied. 
  190. ---------------------------------------------------------
  191.  
  192.  
  193. onSubmit event handler
  194.  
  195. Specifies the JavaScript code to run when a user attempts to submit a form. Return true to allow the form to be submitted; return false to prevent the form from being submitted. 
  196.  
  197. Applies to
  198.  
  199.  
  200.  
  201. form 
  202.  
  203. Examples
  204.  
  205.  
  206.  
  207. In the following example, the onSubmit event handler evaluates the data being submitted to test if it is legal. If the data is legal, the form is submitted; otherwise, the form is not submitted. 
  208.  
  209. form.onSubmit=
  210. "if badFormData(this.form) {
  211.     return false;
  212. } else {
  213.     return true;
  214. }"
  215.  
  216.  
  217.  
  218. ---------------------------------------------------------
  219.  
  220.  
  221. onUnload event handler
  222.  
  223.  
  224.  
  225. An unload event occurs when you exit a document. The onUnload event handler executes JavaScript code when an unload event occurs. 
  226.  
  227. Use the onUnload event handler within either the <BODY>or the <FRAMESET>tags, for example, <BODY onUnload="...">/TT>. 
  228.  
  229. Applies to
  230.  
  231.  
  232.  
  233. document, window 
  234.  
  235. Examples
  236.  
  237.  
  238.  
  239. xxx Examples to be supplied. 
  240.  
  241. See also
  242.  
  243.  
  244.  
  245. onLoad event handler 
  246.